package cn.xiyun.xiyuncc.web.controller;

import cn.xiyun.xiyuncc.dto.SmsCodeDto;
import cn.xiyun.xiyuncc.result.JSONResult;
import cn.xiyun.xiyuncc.service.IVerifycodeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

@RestController
@RequestMapping("/verifycode")
public class VerifycodeController {

    @Autowired
    private IVerifycodeService verifycodeService;

    /**
     * 图形验证码
     * @param imageCodeKey
     * @return
     */
    @GetMapping("/imageCode/{imageCodeKey}")
    public JSONResult imageCode(@PathVariable("imageCodeKey") String imageCodeKey) {
        String BaseS64 = verifycodeService.imageCode(imageCodeKey);
        return new JSONResult().setData(BaseS64);
    }

    /**
     * 短信验证码
     * @param smsCodeDto
     * @return
     * @throws Exception
     */
    @RequestMapping("/sendSmsCode")
    public JSONResult sendSmsCode(@RequestBody @Valid SmsCodeDto smsCodeDto)throws Exception{
        return verifycodeService.sendSmsCode(smsCodeDto);
    }
}
